package com.Vma.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;


public class OutUtil {
	public static JSONObject out(int resultCode,Object result) throws Exception{
		if(resultCode == 200) {
			Date date = new Date();
			String pattern = "yyyy-mm-dd HH:mm:ss";
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("data",  result);
			jsonObject.put("result_code", resultCode);
			jsonObject.put("result_desc", "request successful");
			jsonObject.put("timestamp",sdf.format(date));
			return jsonObject;
		}else {
			Date date = new Date();
			String pattern = "yyyy-mm-dd HH:mm:ss";
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("result_code", resultCode);
			jsonObject.put("result_desc", "request failure");
			jsonObject.put("timestamp",sdf.format(date));
			return jsonObject;
		}
	}
}
